import Cookies from 'js-cookie'
let Base64 = require('js-base64').Base64

const TokenKey = 'Admin-Token'
const RefreshToken = 'Refresh-Token'
const SiderKey = 'Sider-Menu'
const SiderStatus = 'sidebarStatus'
const PageAction = 'pageAction'
const LastVisit = 'lastVisitTime'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function getRefreshToken() {
  return Cookies.get(RefreshToken)
}

export function setRefreshToken(token) {
  return Cookies.set(RefreshToken, token)
}


// 左侧菜单
export function getSiderMenu() {
  return window.localStorage.getItem(SiderKey)
}
export function setSiderMenu() {
  return window.localStorage.setItem(SiderKey, window.JSON.stringify(siderMenu))
}
/*export function removeSiderMenu() {
  return window.localStorage.removeItem(SiderKey)
}*/
// 按钮权限
export function getPageAction() {
  if (window.localStorage.getItem(PageAction)) {
    return Base64.decode(window.localStorage.getItem(PageAction))
  } else {
    return null
  }
}
export function setPageAction(btn) {
  return window.localStorage.setItem(PageAction, Base64.encode(btn))
}
// 清空所有缓存
export function clearAllCache() {
  Cookies.remove(TokenKey)
  Cookies.remove(RefreshToken)
  Cookies.remove(SiderStatus)
  window.localStorage.removeItem(SiderKey)
  window.localStorage.removeItem(PageAction)
  window.sessionStorage.removeItem(LastVisit)
}

const siderMenu = {
  "children": [
  
  {
    "children": null,
   "data": {
    "code": "index",
    "extend":"{\"icon\":\"iconfont icon-shouye-\",\"url\":\"/admin/model/index\"}",
    "menuType": "SYSTEM",
    "name": "首页"
    },
    "id": 13,
    "level": 1,
    "parentId": 0
 
  },
    {
  
  "children": [
    {
      "children": null,
        "data": {
        "code": "appadmin",
        "extend":"{\"icon\":\"iconfont icon-xitongguanli-\",\"url\":\"/admin/model/bannerMaintain\"}",
        "menuType": "SYSTEM",
        "name": "banner维护"
        },
        "id": 4,
        "level": 2,
        "parentId": 1
    },
    {
    "children": null,
        "data": {
        "code": "appadmin",
        "extend":"{\"icon\":\"iconfont icon-xitongguanli-\",\"url\":\"/admin/model/financialPlan\"}",
        "menuType": "SYSTEM",
        "name": "金融方案列表"
        },
        "id": 5,
        "level": 2,
        "parentId": 1
    },
    {
    "children": null,
        "data": {
        "code": "appadmin",
        "extend":"{\"icon\":\"iconfont icon-xitongguanli-\",\"url\":\"/admin/model/appraisal\"}",
        "menuType": "SYSTEM",
        "name": "快速估值记录"
        },
        "id": 6,
        "level": 2,
        "parentId": 1
    },
    {
    "children": null,
        "data": {
        "code": "appadmin",
        "extend":"{\"icon\":\"iconfont icon-xitongguanli-\",\"url\":\"/admin/model/mortgageRecords\"}",
        "menuType": "SYSTEM",
        "name": "有车想抵记录"
        },
        "id": 7,
        "level": 2,
        "parentId": 1
    },
    {
    "children": null,
        "data": {
        "code": "appadmin",
        "extend":"{\"icon\":\"iconfont icon-xitongguanli-\",\"url\":\"/admin/model/intentionRecords\"}",
        "menuType": "SYSTEM",
        "name": "卖车意向记录"
        },
        "id": 8,
        "level": 2,
        "parentId": 1
    },
    {
    "children": null,
        "data": {
        "code": "appadmin",
        "extend":"{\"icon\":\"iconfont icon-xitongguanli-\",\"url\":\"/admin/model/photoPlan\"}",
        "menuType": "SYSTEM",
        "name": "优先审批拍照方案"
        },
        "id": 9,
        "level": 2,
        "parentId": 1
    }
    ],
    "data": {
    "code": "appadmin",
    "extend":"{\"icon\":\"iconfont icon-xitongguanli-\",\"url\":\"/admin\"}",
    "menuType": "SYSTEM",
    "name": "页面管理"
    },
    "id": 1,
    "level": 1,
    "parentId": 0
  },
  {
   "children": [
    {
    "children": null,
     "data": {
      "code": "orderMng",
      "extend":"{\"icon\":\"iconfont icon-xitongguanli-\",\"url\":\"/admin/model/appraisalOrder\"}",
      "menuType": "SYSTEM",
      "name": "车况鉴定订单"
      },
      "id": 10,
      "level": 1,
        "parentId": 2                           
    }
   ],
   "data": {
    "code": "orderMng",
    "extend":"{\"icon\":\"iconfont icon-xitongguanli-\",\"url\":\"/admin\"}",
    "menuType": "SYSTEM",
    "name": "订单管理"
    },
    "id": 2,
    "level": 1,
    "parentId": 0
  },
  {
  "children": [
  {"children": null,
   "data": {
    "code": "userMng",
    "extend":"{\"icon\":\"iconfont icon-xitongguanli-\",\"url\":\"/admin/model/feedback\"}",
    "menuType": "SYSTEM",
    "name": "用户反馈"
    },
    "id": 11,
    "level": 1,
    "parentId": 3
  },
  {"children": null,
   "data": {
    "code": "userMng",
    "extend":"{\"icon\":\"iconfont icon-xitongguanli-\",\"url\":\"/admin/model/account\"}",
    "menuType": "SYSTEM",
    "name": "用户账号"
    },
    "id": 12,
    "level": 1,
    "parentId": 3
  }
  ],
   "data": {
    "code": "userMng",
    "extend":"{\"icon\":\"iconfont icon-xitongguanli-\",\"url\":\"/admin\"}",
    "menuType": "SYSTEM",
    "name": "APP用户管理"
    },
    "id": 3,
    "level": 1,
    "parentId": 0
  }
  ],
  "data": {
    "code": "cheegu",
    "extend": null,
    "menuType": "ROOT",
    "name": "车e估"
  },
  "id": 0,
  "level": 0,
  "parentId": 0
}